

import java.util.Calendar;

public class SummerTimeChecks {
	
	public static Calendar correctSummerTime(Calendar datum) {
		if (!isDatumSummertime(datum))
			datum.add(Calendar.HOUR, -1);
		return datum;
	}

	private static boolean isDatumSummertime(Calendar datum) {
		int year = datum.get(Calendar.YEAR);
		if (datum.after(getSummertimeStart(year)) && datum.before(getSummertimeEnd(year))) {
			return true;
		}
		return false;
	}

	public static Calendar getSummertimeStart(int year) {
		Calendar summertimeStart = Calendar.getInstance();
		summertimeStart.set(Calendar.YEAR, year);
		summertimeStart.set(Calendar.MONTH, Calendar.MARCH);
		summertimeStart.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		summertimeStart.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1);

		return summertimeStart;

	}

	public static Calendar getSummertimeEnd(int year) {
		Calendar summertimeEnd = Calendar.getInstance();
		summertimeEnd.set(Calendar.YEAR, year);
		summertimeEnd.set(Calendar.MONTH, Calendar.OCTOBER);
		summertimeEnd.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		summertimeEnd.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1);
		return summertimeEnd;
	}
	
}